﻿
using HuiZe.education.Model;
using HuiZe.education.Resource.Controls;
using HuiZe.education.ViewModel;
using System;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using YuanCode.Control.Controls;

namespace HuiZe.education.View
{
    /// <summary>
    /// SelectChapterView.xaml 的交互逻辑
    /// </summary>
    public partial class NextChapterView : HuiZeWindow
    {
        public PlanLessonViewModel planModel { get; set; }
        public NextChapterView()
        {
            InitializeComponent();
            this.MaxHeight = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height + 10;
            this.MaxWidth = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width + 10;
            Loaded += ResourceView_Loaded;
        }
      

        private void ResourceView_Loaded(object sender, RoutedEventArgs e)
        {
            planModel = DataContext as PlanLessonViewModel;
            if (planModel.SeletedResCount != null)
            planModel.SeletedResCount = 0;
            //PlanLessonViewModel planLessoniewModel = DataContext as PlanLessonViewModel;
            //planModel = planLessoniewModel;
            //planLessoniewModel.nextChapterView = this;
            //var list = planLessoniewModel.GetzjTagsList();
            //Courses.Children.Clear();
            //foreach (var item in list)
            //{
            //    CustomRadioButton radioButton = new CustomRadioButton
            //    {
            //        Width = 100,
            //        Height = 40,
            //        Margin = new Thickness(5, 0, 0, 0),
            //        HorizontalAlignment = HorizontalAlignment.Left,
            //        Content = item.tag_name,
            //        CornerRadius = new CornerRadius(6),
            //        FontSize = 16,
            //        //IsChecked = true,
            //        NomalBackground = Brushes.White,
            //        NomalForground = Brushes.Black,
            //        SelectedBackground = Brushes.White,
            //        SelectedForground = Brushes.Blue,
            //        Template = (ControlTemplate)FindResource("backRadioTemplate"),
            //    };
            //    radioButton.Click += CustomRadioButton_Click_1;
            //    Courses.Children.Add(radioButton);

            //}

        }
        
       




        private void root_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if ((bool)e.NewValue)
            {
                BeginAnimation(OpacityProperty, (DoubleAnimation)FindResource("show"));
            }
        }

        private void YCButton_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void CustomRadioButton_Click_1(object sender, RoutedEventArgs e)
        {
            PlanLessonViewModel planLessoniewModel = DataContext as PlanLessonViewModel;

            CustomRadioButton btn = sender as CustomRadioButton;
            string type = btn.Content.ToString();
            var list = planLessoniewModel.GetzjResourcesCourseList(type);
            kJWrap.Children.Clear();
            foreach (var item in list)
            {

                WrapPanel stack = new WrapPanel
                {
                    Width = 450,
                    Height = 30,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment = VerticalAlignment.Top,
                    Orientation = Orientation.Horizontal,
                };
                YCCheckBox chk = new YCCheckBox
                {
                    Content = item.resources_name,
                    Height = 30,
                    Width = 350,
                    FontSize = 24,
                    HorizontalAlignment = HorizontalAlignment.Left,
                    VerticalAlignment = VerticalAlignment.Top,
                    Margin = new Thickness(0, 0, 0, 0),
                    //Template = (ControlTemplate)FindResource("YCCheckBoxTemplate"),
                    BorderBrush = Brushes.Cyan,
                    ImageHeight = 16,
                    IsChecked = false,
                    ImageWidht = 16,
                    NomalImageSource = new BitmapImage(new Uri("pack://application:,,,/HuiZe.education.Resource;component/Images/Login/chk_no.png")),
                    SelectedImageSource = new BitmapImage(new Uri("pack://application:,,,/HuiZe.education.Resource;component/Images/Login/记住密码.png")),
                    YCBorderThickness = new Thickness(2),
                };
                chk.Click += YCCheckBox_Checked;

                //Label lb = new Label
                //{
                //    Height = 30,
                //    Width = 80,
                //    Content = item.res_type_text,
                //    Margin = new Thickness(3, 0, 0, 0),
                //    HorizontalAlignment = HorizontalAlignment.Left,
                //    VerticalAlignment = VerticalAlignment.Top,
                //};
                stack.Children.Add(chk);
                //stack.Children.Add(lb);
                //ResroucesItem.Children.Add(stack);
                kJWrap.Children.Add(stack);
            }

        }

        private void YCCheckBox_Checked(object sender, System.Windows.RoutedEventArgs e)
        {
            YCCheckBox chk = sender as YCCheckBox;
            if (chk.IsChecked == true)
            {
                string content = chk.Content.ToString();
                planModel.Setattachment_ids(0, content);
                planModel.SeletedResCount++;
                //this.Close();
            }
            else 
            {
                string content = chk.Content.ToString();
                planModel.RemoveSetattachment_ids(0, content);
                planModel.SeletedResCount--;
            }
        }

        private void YCButton_Click_2(object sender, RoutedEventArgs e)
        {

        }
        private void YCButton_Click_1(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
